package com.ktgj.hotel.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ktgj.common.core.constant.BusinessTypeConstants;
import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.pay.api.domain.YeeBaoResultApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.hotel.mapper.HotelOrderPaydetailMapper;
import com.ktgj.hotel.domain.HotelOrderPaydetail;
import com.ktgj.hotel.service.IHotelOrderPaydetailService;

/**
 * 支付明细
Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@Service
public class HotelOrderPaydetailServiceImpl implements IHotelOrderPaydetailService 
{
    @Autowired
    private HotelOrderPaydetailMapper hotelOrderPaydetailMapper;

    /**
     * 查询支付明细

     * 
     * @param paydetailid 支付明细
ID
     * @return 支付明细

     */
    @Override
    public HotelOrderPaydetail selectHotelOrderPaydetailById(Long paydetailid)
    {
        return hotelOrderPaydetailMapper.selectHotelOrderPaydetailById(paydetailid);
    }

    /**
     * 查询支付明细
     *
     * @param orderid 订单ID
     * @return 支付明细

     */
    @Override
    public HotelOrderPaydetail selectHotelOrderPaydetailByorderId(Long orderid) {
        return hotelOrderPaydetailMapper.selectHotelOrderPaydetailByorderId(orderid);
    }

    /**
     * 查询支付明细
列表
     * 
     * @param hotelOrderPaydetail 支付明细

     * @return 支付明细

     */
    @Override
    public List<HotelOrderPaydetail> selectHotelOrderPaydetailList(HotelOrderPaydetail hotelOrderPaydetail)
    {
        return hotelOrderPaydetailMapper.selectHotelOrderPaydetailList(hotelOrderPaydetail);
    }

    /**
     * 新增支付明细

     * 
     * @param hotelOrderPaydetail 支付明细

     * @return 结果
     */
    @Override
    public int insertHotelOrderPaydetail(HotelOrderPaydetail hotelOrderPaydetail)
    {
        return hotelOrderPaydetailMapper.insertHotelOrderPaydetail(hotelOrderPaydetail);
    }

    /**
     * 修改支付明细

     * 
     * @param hotelOrderPaydetail 支付明细

     * @return 结果
     */
    @Override
    public int updateHotelOrderPaydetail(HotelOrderPaydetail hotelOrderPaydetail)
    {
        return hotelOrderPaydetailMapper.updateHotelOrderPaydetail(hotelOrderPaydetail);
    }

    /**
     * 修改支付明细
     *
     * @param hotelOrderPaydetail 支付明细
     * @return 结果
     */
    @Override
    public int updateOrderPaydetailByOrderId(HotelOrderPaydetail hotelOrderPaydetail) {
        return hotelOrderPaydetailMapper.updateOrderPaydetailByOrderId(hotelOrderPaydetail);
    }

    /**
     * 批量删除支付明细

     * 
     * @param paydetailids 需要删除的支付明细
ID
     * @return 结果
     */
    @Override
    public int deleteHotelOrderPaydetailByIds(Long[] paydetailids)
    {
        return hotelOrderPaydetailMapper.deleteHotelOrderPaydetailByIds(paydetailids);
    }

    /**
     * 删除支付明细
信息
     * 
     * @param paydetailid 支付明细
ID
     * @return 结果
     */
    @Override
    public int deleteHotelOrderPaydetailById(Long paydetailid)
    {
        return hotelOrderPaydetailMapper.deleteHotelOrderPaydetailById(paydetailid);
    }

    /**
     * 新增酒店支付信息
     * */
    @Override
    public int addHotelOrderPaydetail(YeeBaoResultApi yeeBaoResultApi, Map<String, Object> map) {
        HotelOrderPaydetail hotelOrderPaydetail = new HotelOrderPaydetail();
        hotelOrderPaydetail.setTradeorderid(yeeBaoResultApi.getTrxId());//交易记录编号
        //本接口为信用卡支付
        hotelOrderPaydetail.setPaytype(BusinessTypeConstants.BankCredit.getValue());//支付类型：1、信用卡 2、银联语音 3、微信支付 4、支付宝 5差旅 0:非卡，6:、储蓄卡  75、一网通；【线下支付用：10：快钱，20：网银，30：易宝，40：汇款:，50：银联卡。】
        hotelOrderPaydetail.setAccountbank(map.get("bankName").toString());//发卡行
        hotelOrderPaydetail.setCardnum(map.get("cardNumber").toString());//卡号
        hotelOrderPaydetail.setCardholdname(map.get("cardholder").toString());//持卡人姓名
        hotelOrderPaydetail.setCardlimit(map.get("creditCardTime").toString());//有效期
        hotelOrderPaydetail.setCvv2(map.get("Cvv2").toString());//验证码CVV2
        hotelOrderPaydetail.setCredentialstypecode(EmHelper.CertificateType.ID_CARD.getValue());//证件类型
        hotelOrderPaydetail.setCredentialsnumber(map.get("custCertificateNo").toString());//证件号码
        hotelOrderPaydetail.setAmount(new BigDecimal(map.get("moneyAmout").toString()));//金额
        hotelOrderPaydetail.setCardtel(map.get("contractPhoneOne").toString());//开卡手机号
        hotelOrderPaydetail.setPaystatus(1l);//1消费成功,2消费失败
        hotelOrderPaydetail.setIsonline("onLine");//线下，1,线上
        hotelOrderPaydetail.setIsconfirm("true");//0：未确认 1：已确认
        hotelOrderPaydetail.setConfirmoptime(new Date());//确认操作时间
        hotelOrderPaydetail.setPartnerid(11l);//支付合作商  11:易宝；1:快钱；0:未知；12:易宝Web网关；21:微信App；22:微信Web；23:微信Native；31:支付宝App；32:支付宝web；41:网银在线Wap；43:网银在线Api；51:广易联语音；61:连连支付；71:交通银行；72:银联在线web；73:银联App；81:汇付天下web；91:联动优势Api；99:接口测试；101:苹果支付；111:三星支付；121:小米支付
        hotelOrderPaydetail.setOrderid(Long.valueOf(map.get("jsjOrderId").toString()));//订单号
        hotelOrderPaydetail.setOrdertype(2l);//订单类型 1现付 2预付
        hotelOrderPaydetail.setHmac(yeeBaoResultApi.getHmac());//易宝支付签名
        int i = hotelOrderPaydetailMapper.insertHotelOrderPaydetail(hotelOrderPaydetail);
        return i;
    }

    /**
     * 添加交际记录号
     * */
    @Override
    public int updateHotelOrderPaydetailByOrderNum(HotelOrderPaydetail hotelOrderPaydetail) {
        int i = hotelOrderPaydetailMapper.updateHotelOrderPaydetailByOrderNum(hotelOrderPaydetail);
        return i;
    }
}
